{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cedc6fab",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import os\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.animation as animation\n",
    "from IPython.display import HTML,display,Image\n",
    "from moviepy.video.compositing.CompositeVideoClip import clips_array\n",
    "\n",
    "def f_show(frame):\n",
    "    plt.axis(\"off\")\n",
    "    plt.imshow(frame)\n",
    "    plt.show()\n",
    "\n",
    "def clips_show(clips, t=15):\n",
    "    f_show(clips_array([clips]).get_frame(t))\n",
    "\n",
    "def pre_show_clip(clip):\n",
    "    plt.subplot(221), plt.imshow(clip.get_frame(5)), plt.axis(\"off\")\n",
    "    plt.subplot(222), plt.imshow(clip.get_frame(15)), plt.axis(\"off\")\n",
    "    plt.subplot(223), plt.imshow(clip.get_frame(30)), plt.axis(\"off\")\n",
    "    plt.subplot(224), plt.imshow(clip.get_frame(45)), plt.axis(\"off\")\n",
    "    plt.show()\n",
    "\n",
    "def display_video(clip, jump=5):\n",
    "    t = 0\n",
    "    frame_lists = []\n",
    "    fig = plt.figure()\n",
    "\n",
    "    while t < clip.end:\n",
    "        frame = clip.get_frame(t)\n",
    "        plt.axis(\"off\")\n",
    "        frame_lists.append([plt.imshow(frame)])\n",
    "        t += jump\n",
    "\n",
    "\n",
    "    # interval:每一帧显示多久  repeat_delay：全部播放完毕后多久重放\n",
    "    ani = animation.ArtistAnimation(fig, frame_lists, interval=500, blit=True, repeat_delay=1000)\n",
    "    # ani.save(\"movie.mp4\")\n",
    "    display(HTML(ani.to_html5_video()))\n",
    "\n",
    "\n",
    "\n",
    "import moviepy.video.fx.all as vfx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "['AvantGarde-Book',\n 'AvantGarde-BookOblique',\n 'AvantGarde-Demi',\n 'AvantGarde-DemiOblique',\n 'Bookman-Demi',\n 'Bookman-DemiItalic',\n 'Bookman-Light',\n 'Bookman-LightItalic',\n 'Courier',\n 'Courier-Bold',\n 'Courier-BoldOblique',\n 'Courier-Oblique',\n 'fixed',\n 'Helvetica',\n 'Helvetica-Bold',\n 'Helvetica-BoldOblique',\n 'Helvetica-Narrow',\n 'Helvetica-Narrow-Bold',\n 'Helvetica-Narrow-BoldOblique',\n 'Helvetica-Narrow-Oblique',\n 'Helvetica-Oblique',\n 'NewCenturySchlbk-Bold',\n 'NewCenturySchlbk-BoldItalic',\n 'NewCenturySchlbk-Italic',\n 'NewCenturySchlbk-Roman',\n 'Palatino-Bold',\n 'Palatino-BoldItalic',\n 'Palatino-Italic',\n 'Palatino-Roman',\n 'Symbol',\n 'Times-Bold',\n 'Times-BoldItalic',\n 'Times-Italic',\n 'Times-Roman',\n 'Bitstream-Charter',\n 'Bitstream-Charter-Bold',\n 'Bitstream-Charter-Bold-Italic',\n 'Bitstream-Charter-Italic',\n 'Century-Schoolbook-L-Bold',\n 'Century-Schoolbook-L-Bold-Italic',\n 'Century-Schoolbook-L-Italic',\n 'Century-Schoolbook-L-Roman',\n 'Courier-10-Pitch',\n 'Courier-10-Pitch-Bold',\n 'Courier-10-Pitch-Bold-Italic',\n 'Courier-10-Pitch-Italic',\n 'Deepin-OpenSymbol-2',\n 'Deepin-OpenSymbol-3',\n 'Deepin-OpenSymbol-4-Regular',\n 'Deepin-OpenSymbol-5-Regular',\n 'Deepin-OpenSymbol-6-Regular',\n 'Deepin-OpenSymbol-Regular',\n 'DejaVu-Sans',\n 'DejaVu-Sans-Bold',\n 'DejaVu-Sans-Mono',\n 'DejaVu-Sans-Mono-Bold',\n 'DejaVu-Serif',\n 'DejaVu-Serif-Bold',\n 'DejaVuMathTeXGyre-Regular',\n 'Dingbats',\n 'Droid-Sans-Fallback',\n 'Liberation-Mono',\n 'Liberation-Mono-Bold',\n 'Liberation-Mono-Bold-Italic',\n 'Liberation-Mono-Italic',\n 'Liberation-Sans',\n 'Liberation-Sans-Bold',\n 'Liberation-Sans-Bold-Italic',\n 'Liberation-Sans-Italic',\n 'Liberation-Sans-Narrow',\n 'Liberation-Sans-Narrow-Bold',\n 'Liberation-Sans-Narrow-Bold-Italic',\n 'Liberation-Sans-Narrow-Italic',\n 'Liberation-Serif',\n 'Liberation-Serif-Bold',\n 'Liberation-Serif-Bold-Italic',\n 'Liberation-Serif-Italic',\n 'Lohit-Devanagari',\n 'Nimbus-Mono-L',\n 'Nimbus-Mono-L-Bold',\n 'Nimbus-Mono-L-Bold-Oblique',\n 'Nimbus-Mono-L-Regular-Oblique',\n 'Nimbus-Roman-No9-L',\n 'Nimbus-Roman-No9-L-Medium',\n 'Nimbus-Roman-No9-L-Medium-Italic',\n 'Nimbus-Roman-No9-L-Regular-Italic',\n 'Nimbus-Sans-L',\n 'Nimbus-Sans-L-Bold',\n 'Nimbus-Sans-L-Bold-Condensed',\n 'Nimbus-Sans-L-Bold-Condensed-Italic',\n 'Nimbus-Sans-L-Bold-Italic',\n 'Nimbus-Sans-L-Regular-Condensed',\n 'Nimbus-Sans-L-Regular-Condensed-Italic',\n 'Nimbus-Sans-L-Regular-Italic',\n 'Noto-Kufi-Arabic',\n 'Noto-Kufi-Arabic-Bold',\n 'Noto-Mono',\n 'Noto-Music-Regular',\n 'Noto-Naskh-Arabic',\n 'Noto-Naskh-Arabic-Bold',\n 'Noto-Nastaliq-Urdu-Bold',\n 'Noto-Nastaliq-Urdu-Regular',\n 'Noto-Sans-Adlam-Regular',\n 'Noto-Sans-Adlam-Unjoined-Regular',\n 'Noto-Sans-Anatolian-Hieroglyphs-Regular',\n 'Noto-Sans-Arabic-Bold',\n 'Noto-Sans-Arabic-Regular',\n 'Noto-Sans-Armenian-Bold',\n 'Noto-Sans-Armenian-Regular',\n 'Noto-Sans-Avestan-Regular',\n 'Noto-Sans-Bamum-Regular',\n 'Noto-Sans-Bassa-Vah-Regular',\n 'Noto-Sans-Batak-Regular',\n 'Noto-Sans-Bengali-Bold',\n 'Noto-Sans-Bengali-Regular',\n 'Noto-Sans-Bhaiksuki-Regular',\n 'Noto-Sans-Bold',\n 'Noto-Sans-Bold-Italic',\n 'Noto-Sans-Brahmi-Regular',\n 'Noto-Sans-Buginese-Regular',\n 'Noto-Sans-Buhid-Regular',\n 'Noto-Sans-Canadian-Aboriginal-Bold',\n 'Noto-Sans-Canadian-Aboriginal-Regular',\n 'Noto-Sans-Carian-Regular',\n 'Noto-Sans-Caucasian-Albanian-Regular',\n 'Noto-Sans-Chakma-Regular',\n 'Noto-Sans-Cham-Bold',\n 'Noto-Sans-Cham-Regular',\n 'Noto-Sans-Cherokee-Bold',\n 'Noto-Sans-Cherokee-Regular',\n 'Noto-Sans-CJK-JP-Bold',\n 'Noto-Sans-CJK-JP-Regular',\n 'Noto-Sans-CJK-KR-Bold',\n 'Noto-Sans-CJK-KR-Regular',\n 'Noto-Sans-CJK-SC-Bold',\n 'Noto-Sans-CJK-SC-Regular',\n 'Noto-Sans-CJK-TC-Bold',\n 'Noto-Sans-CJK-TC-Regular',\n 'Noto-Sans-Coptic-Regular',\n 'Noto-Sans-Cuneiform-Regular',\n 'Noto-Sans-Cypriot-Regular',\n 'Noto-Sans-Deseret-Regular',\n 'Noto-Sans-Devanagari-Bold',\n 'Noto-Sans-Devanagari-Regular',\n 'Noto-Sans-Display-Bold',\n 'Noto-Sans-Display-Bold-Italic',\n 'Noto-Sans-Display-Italic',\n 'Noto-Sans-Display-Regular',\n 'Noto-Sans-Duployan-Regular',\n 'Noto-Sans-Egyptian-Hieroglyphs-Regular',\n 'Noto-Sans-Elbasan-Regular',\n 'Noto-Sans-Ethiopic-Bold',\n 'Noto-Sans-Ethiopic-Regular',\n 'Noto-Sans-Georgian-Bold',\n 'Noto-Sans-Georgian-Regular',\n 'Noto-Sans-Glagolitic-Regular',\n 'Noto-Sans-Gothic-Regular',\n 'Noto-Sans-Grantha-Regular',\n 'Noto-Sans-Gujarati',\n 'Noto-Sans-Gujarati-Bold',\n 'Noto-Sans-Gurmukhi',\n 'Noto-Sans-Gurmukhi-Bold',\n 'Noto-Sans-Hanunoo-Regular',\n 'Noto-Sans-Hatran-Regular',\n 'Noto-Sans-Hebrew-Bold',\n 'Noto-Sans-Hebrew-Regular',\n 'Noto-Sans-Imperial-Aramaic-Regular',\n 'Noto-Sans-Inscriptional-Pahlavi-Regular',\n 'Noto-Sans-Inscriptional-Parthian-Regular',\n 'Noto-Sans-Italic',\n 'Noto-Sans-Javanese',\n 'Noto-Sans-Javanese-Bold',\n 'Noto-Sans-Kaithi-Regular',\n 'Noto-Sans-Kannada-Bold',\n 'Noto-Sans-Kannada-Regular',\n 'Noto-Sans-Kayah-Li-Regular',\n 'Noto-Sans-Kharoshthi-Regular',\n 'Noto-Sans-Khmer-Bold',\n 'Noto-Sans-Khmer-Regular',\n 'Noto-Sans-Khojki-Regular',\n 'Noto-Sans-Khudawadi-Regular',\n 'Noto-Sans-Lao-Bold',\n 'Noto-Sans-Lao-Regular',\n 'Noto-Sans-Lepcha-Regular',\n 'Noto-Sans-Limbu-Regular',\n 'Noto-Sans-Linear-A-Regular',\n 'Noto-Sans-Linear-B-Regular',\n 'Noto-Sans-Lisu-Regular',\n 'Noto-Sans-Lycian-Regular',\n 'Noto-Sans-Lydian-Regular',\n 'Noto-Sans-Mahajani-Regular',\n 'Noto-Sans-Malayalam-Bold',\n 'Noto-Sans-Malayalam-Regular',\n 'Noto-Sans-Mandaic-Regular',\n 'Noto-Sans-Manichaean-Regular',\n 'Noto-Sans-Marchen-Regular',\n 'Noto-Sans-Math-Regular',\n 'Noto-Sans-Meetei-Mayek-Regular',\n 'Noto-Sans-Mende-Kikakui-Regular',\n 'Noto-Sans-Meroitic-Regular',\n 'Noto-Sans-Miao-Regular',\n 'Noto-Sans-Modi-Regular',\n 'Noto-Sans-Mongolian',\n 'Noto-Sans-Mono-Bold',\n 'Noto-Sans-Mono-CJK-JP-Bold',\n 'Noto-Sans-Mono-CJK-JP-Regular',\n 'Noto-Sans-Mono-CJK-KR-Bold',\n 'Noto-Sans-Mono-CJK-KR-Regular',\n 'Noto-Sans-Mono-CJK-SC-Bold',\n 'Noto-Sans-Mono-CJK-SC-Regular',\n 'Noto-Sans-Mono-CJK-TC-Bold',\n 'Noto-Sans-Mono-CJK-TC-Regular',\n 'Noto-Sans-Mono-Regular',\n 'Noto-Sans-Mro-Regular',\n 'Noto-Sans-Multani-Regular',\n 'Noto-Sans-Myanmar-Bold',\n 'Noto-Sans-Myanmar-Regular',\n 'Noto-Sans-Nabataean-Regular',\n 'Noto-Sans-New-Tai-Lue-Regular',\n 'Noto-Sans-Newa-Regular',\n 'Noto-Sans-NKo-Regular',\n 'Noto-Sans-Ogham-Regular',\n 'Noto-Sans-Ol-Chiki-Regular',\n 'Noto-Sans-Old-Hungarian-Regular',\n 'Noto-Sans-Old-Italic-Regular',\n 'Noto-Sans-Old-North-Arabian-Regular',\n 'Noto-Sans-Old-Permic-Regular',\n 'Noto-Sans-Old-Persian-Regular',\n 'Noto-Sans-Old-South-Arabian-Regular',\n 'Noto-Sans-Old-Turkic-Regular',\n 'Noto-Sans-Oriya',\n 'Noto-Sans-Oriya-Bold',\n 'Noto-Sans-Osage-Regular',\n 'Noto-Sans-Osmanya-Regular',\n 'Noto-Sans-Pahawh-Hmong-Regular',\n 'Noto-Sans-Palmyrene-Regular',\n 'Noto-Sans-Pau-Cin-Hau-Regular',\n 'Noto-Sans-PhagsPa-Regular',\n 'Noto-Sans-Phoenician-Regular',\n 'Noto-Sans-Psalter-Pahlavi-Regular',\n 'Noto-Sans-Regular',\n 'Noto-Sans-Rejang-Regular',\n 'Noto-Sans-Runic-Regular',\n 'Noto-Sans-Samaritan-Regular',\n 'Noto-Sans-Saurashtra-Regular',\n 'Noto-Sans-Sharada-Regular',\n 'Noto-Sans-Shavian-Regular',\n 'Noto-Sans-Sinhala-Bold',\n 'Noto-Sans-Sinhala-Regular',\n 'Noto-Sans-Sora-Sompeng-Regular',\n 'Noto-Sans-Sundanese-Regular',\n 'Noto-Sans-Syloti-Nagri-Regular',\n 'Noto-Sans-Symbols-Bold',\n 'Noto-Sans-Symbols-Regular',\n 'Noto-Sans-Symbols2-Regular',\n 'Noto-Sans-Syriac-Eastern',\n 'Noto-Sans-Syriac-Estrangela',\n 'Noto-Sans-Syriac-Regular',\n 'Noto-Sans-Syriac-Western',\n 'Noto-Sans-Tagalog-Regular',\n 'Noto-Sans-Tagbanwa-Regular',\n 'Noto-Sans-Tai-Le-Regular',\n 'Noto-Sans-Tai-Tham',\n 'Noto-Sans-Tai-Viet-Regular',\n 'Noto-Sans-Takri-Regular',\n 'Noto-Sans-Tamil-Bold',\n 'Noto-Sans-Tamil-Regular',\n 'Noto-Sans-Telugu',\n 'Noto-Sans-Telugu-Bold',\n 'Noto-Sans-Thaana',\n 'Noto-Sans-Thaana-Bold',\n 'Noto-Sans-Thai-Bold',\n 'Noto-Sans-Thai-Regular',\n 'Noto-Sans-Tibetan',\n 'Noto-Sans-Tibetan-Bold',\n 'Noto-Sans-Tifinagh-Regular',\n 'Noto-Sans-Tirhuta-Regular',\n 'Noto-Sans-Ugaritic-Regular',\n 'Noto-Sans-Vai-Regular',\n 'Noto-Sans-Warang-Citi-Regular',\n 'Noto-Sans-Yi-Regular',\n 'Noto-Serif-Ahom-Regular',\n 'Noto-Serif-Armenian-Bold',\n 'Noto-Serif-Armenian-Regular',\n 'Noto-Serif-Balinese-Regular',\n 'Noto-Serif-Bengali',\n 'Noto-Serif-Bengali-Bold',\n 'Noto-Serif-Bold',\n 'Noto-Serif-Bold-Italic',\n 'Noto-Serif-CJK-JP',\n 'Noto-Serif-CJK-JP-Bold',\n 'Noto-Serif-CJK-KR',\n 'Noto-Serif-CJK-KR-Bold',\n 'Noto-Serif-CJK-SC',\n 'Noto-Serif-CJK-SC-Bold',\n 'Noto-Serif-CJK-TC',\n 'Noto-Serif-CJK-TC-Bold',\n 'Noto-Serif-Devanagari',\n 'Noto-Serif-Devanagari-Bold',\n 'Noto-Serif-Display-Bold',\n 'Noto-Serif-Display-Bold-Italic',\n 'Noto-Serif-Display-Italic',\n 'Noto-Serif-Display-Regular',\n 'Noto-Serif-Ethiopic-Bold',\n 'Noto-Serif-Ethiopic-Regular',\n 'Noto-Serif-Georgian-Bold',\n 'Noto-Serif-Georgian-Regular',\n 'Noto-Serif-Gujarati-Bold',\n 'Noto-Serif-Gujarati-Regular',\n 'Noto-Serif-Gurmukhi-Bold',\n 'Noto-Serif-Gurmukhi-Regular',\n 'Noto-Serif-Hebrew-Bold',\n 'Noto-Serif-Hebrew-Regular',\n 'Noto-Serif-Italic',\n 'Noto-Serif-Kannada-Bold',\n 'Noto-Serif-Kannada-Regular',\n 'Noto-Serif-Khmer-Bold',\n 'Noto-Serif-Khmer-Regular',\n 'Noto-Serif-Lao-Bold',\n 'Noto-Serif-Lao-Regular',\n 'Noto-Serif-Malayalam',\n 'Noto-Serif-Malayalam-Bold',\n 'Noto-Serif-Myanmar-Bold',\n 'Noto-Serif-Myanmar-Regular',\n 'Noto-Serif-Regular',\n 'Noto-Serif-Sinhala-Bold',\n 'Noto-Serif-Sinhala-Regular',\n 'Noto-Serif-Tamil-Bold',\n 'Noto-Serif-Tamil-Regular',\n 'Noto-Serif-Tamil-Slanted-Bold',\n 'Noto-Serif-Tamil-Slanted-Regular',\n 'Noto-Serif-Telugu',\n 'Noto-Serif-Telugu-Bold',\n 'Noto-Serif-Thai-Bold',\n 'Noto-Serif-Thai-Regular',\n 'Noto-Serif-Tibetan-Bold',\n 'Noto-Serif-Tibetan-Regular',\n 'Standard-Symbols-L',\n 'Symbola',\n 'Unifont',\n 'Unifont-CSUR',\n 'Unifont-Upper',\n 'URW-Bookman-L-Demi-Bold',\n 'URW-Bookman-L-Demi-Bold-Italic',\n 'URW-Bookman-L-Light',\n 'URW-Bookman-L-Light-Italic',\n 'URW-Chancery-L-Medium-Italic',\n 'URW-Gothic-L-Book',\n 'URW-Gothic-L-Book-Oblique',\n 'URW-Gothic-L-Demi',\n 'URW-Gothic-L-Demi-Oblique',\n 'URW-Palladio-L-Bold',\n 'URW-Palladio-L-Bold-Italic',\n 'URW-Palladio-L-Italic',\n 'URW-Palladio-L-Roman',\n 'WenQuanYi-Micro-Hei',\n 'WenQuanYi-Zen-Hei',\n 'WenQuanYi-Zen-Hei-Mono',\n 'WenQuanYi-Zen-Hei-Sharp']"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from  moviepy.video.VideoClip import TextClip\n",
    "TextClip.list(\"font\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moviepy - Building video credits1.mp4.\n",
      "Moviepy - Writing video credits1.mp4\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                               \r"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moviepy - Done !\n",
      "Moviepy - video ready credits1.mp4\n"
     ]
    }
   ],
   "source": [
    "# 滚动字幕\n",
    "\n",
    "from moviepy.video.compositing.concatenate import concatenate_videoclips\n",
    "from moviepy.editor import VideoFileClip\n",
    "import moviepy.video.fx.all as vfx\n",
    "from  moviepy.video.tools.credits import credits1\n",
    "path = \"credits1.txt\"\n",
    "video_clip = VideoFileClip(path)\n",
    "imgClip = credits1(path, 1920, color='blue', stroke_color='red',\n",
    "             stroke_width=2, font='WenQuanYi-Zen-Hei', fontsize=60, gap=10)#生成字幕剪辑\n",
    "\n",
    "x_speed = x_start = y_start = 0\n",
    "y_speed = 30\n",
    "\n",
    "video = VideoFileClip(\"dde-introduction.mp4\")     # 加载视频文件\n",
    "\n",
    "imgClip = imgClip.fx(vfx.scroll, 30,1920, x_speed, y_speed, x_start, y_start)\n",
    "imgClip = imgClip.set_duration(30).set_fps(video.fps) #给字幕剪辑设置播放时长和fps\n",
    "imgClip.write_videofile(\"credits1.mp4\", fps=30)\n",
    "imgClip.close()\n",
    "video.close()\n",
    "# imgClipList = [imgClip, video]\n",
    "# mixVideo = concatenate_videoclips(imgClipList, method='compose')\n",
    "# mixVideo.write_videofile(\"credits2.mp4\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}